package com.yzh.design.demo.impl;

import com.alibaba.fastjson.JSON;
import com.yzh.design.demo.AuthInfo;
import com.yzh.design.demo.AuthLink;
import com.yzh.design.demo.AuthService;

import java.text.ParseException;
import java.util.Date;

public class Level3AuthLink extends AuthLink {

    public Level3AuthLink(String levelUserId, String userName) throws ParseException {
        super(levelUserId, userName);
    }

    @Override
    public AuthInfo doAuth(String uId, String orderId, Date authDate) {
        Date date = AuthService.queryAuthInfo(uId, orderId);
        if (date == null) {
            return new AuthInfo("0001", "单号：" + orderId, " 状态：待审批", " 负责人：" + userName);
        }
        logger.info(JSON.toJSONString(new AuthInfo("0000", "单号：" + orderId, "状态：三级审批完成", " 时间：" + sf.format(date), " 审批人：" + userName)));

        AuthLink next = super.getNext();
        if (next == null) return new AuthInfo("0000", "审核成功");

        return next.doAuth(uId, orderId, authDate);
    }
}
